package blazingbubble.network.game.strategy;

import blazingbubble.game.Game;
import blazingbubble.game.Result;
import moltencore.network.protocol.GameEndedNotification;
import moltencore.network.protocol.TimeLeft;
import org.apache.log4j.Logger;
import spark.network.protocol.Acknowledgement;
import spark.network.protocol.Base;
import spark.network.protocol.Response;
import spark.network.strategy.IProtocolHandleStrategy;
import spark.utility.OutWrapper;

import java.util.Collection;
import java.util.HashMap;

public class TimeLeftStrategy implements IProtocolHandleStrategy<TimeLeft> {
	private Logger logger = Logger.getLogger(TimeLeftStrategy.class);

	private Game game;

	public TimeLeftStrategy(Game game) {
		this.game = game;
	}

	@Override
	public void handle(TimeLeft packet, OutWrapper<Response> acknowledgement, Collection<Base> additionalData) {
		float timeLeft = packet.getSecondsLeft();
		timeLeft += ((float)packet.getRoundTripTime()) / 1000.0f;
		if(timeLeft < 0) {
			timeLeft = 0;
		}
		game.setTimeLeft(timeLeft);
	}
}